<?php
    include('./request.php');
    include('./config.php');
    $marketName = $result->marketName;
    $marketType = $result->marketType;
    $marketAuthor = $result->marketAuthor;
    $marketEmail = $result->marketEmail;
    $marketPhone = $result->marketPhone;
    $username = $result->username;
    try{
        if($username==""){
            echo "notLogin";
        }else{
        $pdo = new PDO($dsn,$user,$pass);
        $sql = "insert into market(market_name,market_type,market_author,market_email,market_phone)values('".$marketName."','".$marketType."','".$marketAuthor."','".$marketEmail."','".$marketPhone."')";
        $res = $pdo->prepare($sql);
        $res->execute();
        $sql2 = "select user_id from user where user_name = '".$username."'";
        $res2 = $pdo->prepare($sql2);
        $res2->execute();
    if($res){
        if($res2){
            $rea2 = $res2->fetch(PDO::FETCH_ASSOC);
            $userID = $rea2['user_id'];
           $sql3 = "insert into supermarket(user_id,market_name)values(".$userID.",'".$marketName."')";
           $res3 = $pdo->prepare($sql3);
            $res3->execute();
            if($res3){
                echo "ok";

            }else{
                echo "error";
            }
        }else{
            echo "error";
        }
    }else{
        echo "error";
    }
      }
    }catch(PDOException $e){
            echo "error";
    }
?>